package rmmk.framework.gui.featureSelection;

import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JPanel;

import rmmk.algorithms.features.FeatureManager;
import rmmk.algorithms.features.abstraction.AbstractFeatureExtractor;
import rmmk.algorithms.features.fatures.GlobalClassesWordCountExtractor;
import rmmk.algorithms.features.fatures.NumberExtractor;
import rmmk.algorithms.features.fatures.NumbersWordsExtractor;
import rmmk.algorithms.features.fatures.PairsOfWordsExtractor;

public class FeatureSelectionPanel extends JPanel {

	private static final long serialVersionUID = 1L;

	MostFrequentWordsPanel mostFrequentWordPanel;
	PairOfWordsPanel pairOfWordsPanel;
	WordsWithNumbersPanel wordsWithNumbers;
	NumbersExtractorPanel numbersExtractorPanel;

	public FeatureSelectionPanel(FeatureManager fm) {
		super();
		setLayout(new GridLayout(5, 1, 0, 5));
		mostFrequentWordPanel = new MostFrequentWordsPanel();
		add(mostFrequentWordPanel);

		wordsWithNumbers = new WordsWithNumbersPanel();
		add(wordsWithNumbers);

		pairOfWordsPanel = new PairOfWordsPanel();
		add(pairOfWordsPanel);

		numbersExtractorPanel = new NumbersExtractorPanel();
		add(numbersExtractorPanel);

	}

	public ArrayList<AbstractFeatureExtractor> getFeatures() {
		ArrayList<AbstractFeatureExtractor> features = new ArrayList<AbstractFeatureExtractor>();

		if (mostFrequentWordPanel.getFeature() != null) {
			features.add(new GlobalClassesWordCountExtractor(Integer
					.parseInt(mostFrequentWordPanel.getFeature().get(0))));
		}
		if (wordsWithNumbers.getFeature() != null) {

			features.add(new NumbersWordsExtractor());
		}
		if (pairOfWordsPanel.getFeature() != null) {

			features.add(new PairsOfWordsExtractor(Integer
					.parseInt(pairOfWordsPanel.getFeature().get(0))));

		}

		if (numbersExtractorPanel.getFeature() != null) {

			features.add(new NumberExtractor(Integer
					.parseInt(numbersExtractorPanel.getFeature().get(0))));

		}

		return features;
	}

}
